/*
 * User.java
 *
 * Created on July 1, 2007, 1:25 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.atomojo.app.auth;

import java.security.MessageDigest;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

/**
 *
 * @author alex
 */
public class User
{
   
   String alias;
   UUID id;
   String name;
   String email;
   List<String> groups;
   
   /** Creates a new instance of User */
   public User(String alias,UUID id,String name,String email,List<String> groups)
   {
      this.alias = alias;
      this.id = id;
      this.name = name;
      this.email = email;
      this.groups = Collections.unmodifiableList(groups);
   }
   
   public String getAlias()
   {
      return alias;
   }

   public UUID getId()
   {
      return id;
   }

   public String getName()
   {
      return name;
   }

   public String getEmail()
   {
      return email;
   }
   
   public List<String> getGroups() {
      return groups;
   }
   
   private static String[] hex = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
   public static String md5Password(String password)
      throws java.security.NoSuchAlgorithmException
   {
      MessageDigest md5 = MessageDigest.getInstance( "MD5" );
      md5.update( password.getBytes() );
      byte[] b = md5.digest();
      StringBuilder buf = new StringBuilder( b.length * 2 );
      for ( int i = 0; i < b.length; i++ ) {
         int n = b[i];
         if ( n < 0 ) {
            n = 256 + n;
         }
         int d1 = n / 16;
         int d2 = n % 16;
         buf.append( hex[d1] );
         buf.append( hex[d2] );
      }
      return buf.toString();
   }
   
   public static void main(String [] args)
   {
      try {
         for (int i=0; i<args.length; i++) {
            System.out.println(md5Password(args[i]));
         }
      } catch(Exception ex) {
         ex.printStackTrace();
      }
   }
   
}
